package com.thiswhyme.fsplus.sentinel.feign.defaultdegrade;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;

/**
 * @description: 简单降级规则
 * @author: thiswhyme
 * @date: 2021/4/25
 */
public class SimpleDegradeRule {

    /**
     * 降级策略：0.平均响应时长，1.异常比例，2.异常数
     * 参见com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
     */
    private int grade = RuleConstant.DEGRADE_GRADE_RT;

    /**
     * 域值，含义跟随grade决定：0.
     * RT阈值（ms），1.异常率阈值，2.异常个数（个）
     * 参见com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
     */
    private double count = 5000;

    /**
     * 可触发断路的最小请求数（在活动统计时间跨度内）
     * 参见com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
     * @since 1.7.0
     */
    private int minRequestAmount = RuleConstant.DEGRADE_DEFAULT_MIN_REQUEST_AMOUNT;

    /**
     * 降级发生时的降级恢复超时（熔断窗口，秒)
     * 参见com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
     */
    private int timeWindow = 5;

    /**
     * 可触发RT断路的最小连续慢速请求数，降级策略为0时使用
     * 参见com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule
     * @since 1.7.0
     */
    private int rtSlowRequestAmount = RuleConstant.DEGRADE_DEFAULT_SLOW_REQUEST_AMOUNT;

    /**
     * 可触发RT断路的慢速请求率，降级策略为0时使用
     */
    private double slowRatioThreshold = 1.0d;

    /**
     * 统计窗口
     */
    private int statIntervalMs = 1000;

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }

    public double getCount() {
        return count;
    }

    public void setCount(double count) {
        this.count = count;
    }

    public int getMinRequestAmount() {
        return minRequestAmount;
    }

    public void setMinRequestAmount(int minRequestAmount) {
        this.minRequestAmount = minRequestAmount;
    }

    public int getTimeWindow() {
        return timeWindow;
    }

    public void setTimeWindow(int timeWindow) {
        this.timeWindow = timeWindow;
    }

    public int getRtSlowRequestAmount() {
        return rtSlowRequestAmount;
    }

    public void setRtSlowRequestAmount(int rtSlowRequestAmount) {
        this.rtSlowRequestAmount = rtSlowRequestAmount;
    }

    public double getSlowRatioThreshold() {
        return slowRatioThreshold;
    }

    public void setSlowRatioThreshold(double slowRatioThreshold) {
        this.slowRatioThreshold = slowRatioThreshold;
    }

    public int getStatIntervalMs() {
        return statIntervalMs;
    }

    public void setStatIntervalMs(int statIntervalMs) {
        this.statIntervalMs = statIntervalMs;
    }
}
